package com.wenheng.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wenheng.service.CommodityService;
import com.wenheng.vo.entity.EasybuyProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 文恒
 * @Date: 2021/3/22 - 03 - 22 -10:41
 * @Description:com.wenheng.controller
 * @version:1.0
 */
@RestController
public class CommodityController{
    @Autowired
    private CommodityService commodityService;
    @GetMapping("/commodity/findCommodity")
    public Map<String,Object> findCommodity(){
        //PageInfo<EasybuyProduct> pageInfo = new PageInfo<>();  //返回的信息都在这里面
        Map<String,Object> map = new HashMap<>();
        List<EasybuyProduct> list = commodityService.findProduct();
        //pageInfo.setList(commodityService.findProduct());
        map.put("data",list);
        //map.put("page", pageInfo);
        map.put("total",new PageInfo<>(list).getTotal());
        return map;
    }
    //查询出自定id的商品信息
    @GetMapping("/commodity/findSeckill/Commodity")
    public Map<String,Object> findSeckill(@RequestParam("id") Integer id){
        Map<String,Object> map = new HashMap<>();
        map.put("data",commodityService.findSeckill(id));
        return map;
    }
}
